﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.DialogUI {
    import flash.events.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Display.*;
    import Display.MarketUI.*;
    import Display.aswingui.*;
    import Engine.*;

    public class StorageDialogView extends GenericDialogView {

        public static const NUM_MARKET_CELLS:int = 3;

        protected var marketCells:Array;

        public function StorageDialogView(_arg1:Dictionary, _arg2:String){
            super(_arg1, ZLoc.t("Dialogs", (_arg2 + "_message")), _arg2, TYPE_OK, null, "none", GenericDialogView.ICON_POS_BOTTOM);
        }
        override protected function createIconPane():JPanel{
            var _local4:MarketCell;
            var _local5:int;
            var _local6:Item;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.marketCells = new Array();
            var _local2:Array = Global.gameSettings.getBuyableItems("storage");
            var _local3:int;
            while (_local3 < NUM_MARKET_CELLS) {
                _local4 = new MarketCell();
                _local5 = MathUtil.randomIndex(_local2);
                _local6 = _local2[_local5];
                _local2.splice(_local5, 1);
                _local4.setAssetDict(m_assetDict);
                _local4.setCellValue(_local6);
                _local4.setBuyable(false);
                _local4.addEventListener(DataItemEvent.MARKET_BUY, this.onBuy, false, 0, true);
                _local1.append(_local4);
                if ((_local3 + 1) < NUM_MARKET_CELLS){
                    _local1.append(ASwingHelper.horizontalStrut(30));
                };
                _local3++;
            };
            return (_local1);
        }
        override protected function createButtonPanel():JPanel{
            var _local3:JButton;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            if (!Global.isVisiting()){
                _local3 = new CustomButton(ZLoc.t("Dialogs", (m_titleString + "_accept")), null, "GreenButtonUI");
                _local3.addEventListener(MouseEvent.MOUSE_UP, this.onOpenClick, false, 0, true);
                _local1.appendAll(_local3, ASwingHelper.horizontalStrut(5));
            };
            var _local2:JButton = new CustomButton(ZLoc.t("Dialogs", "Cancel"), null, "RedButtonUI");
            _local2.addEventListener(MouseEvent.MOUSE_UP, this.onCancelClick, false, 0, true);
            _local1.append(_local2);
            return (_local1);
        }
        protected function onOpenClick(_arg1:MouseEvent):void{
            countDialogViewAction(ZLoc.t("Dialogs", (m_titleString + "_accept")));
            UI.displayCatalog("farming");
            closeMe();
        }
        protected function onCancelClick(_arg1:MouseEvent):void{
            countDialogViewAction(ZLoc.t("Dialogs", "Cancel"));
            closeMe();
        }
        protected function onBuy(_arg1:DataItemEvent):void{
            closeMe();
            var _local2:MarketEvent = new MarketEvent(MarketEvent.MARKET_BUY, MarketEvent.GENERIC, _arg1.item.name);
            UI.onMarketClick(_local2);
        }

    }
}//package Display.DialogUI 
